package com.hc.model;

import java.io.IOException;
import java.util.HashMap;

import com.hc.R;
import com.hc.util.SoundCommand;

import android.R.integer;
import android.app.Activity;
import android.content.Context;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.SoundPool;
import android.provider.MediaStore.Audio.Media;
import android.widget.Toast;

public class MyMediaPlayer {
//	Activity context;
//	public MyMediaPlayer(Activity context,int ID) {
		// TODO Auto-generated constructor stub
//		this.context = context;
//		initSounds();
//	}
//	int streamVolume; // 音量
//	private SoundPool soundPool;
//	private HashMap<Integer,Integer> soundPoolMap;
//	
//	public void initSounds() {
//		// TODO Auto-generated method stub
//		soundPool = new SoundPool(100, AudioManager.STREAM_MUSIC, 100);
//		soundPoolMap = new HashMap<Integer, Integer>();
//		AudioManager mgr = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
//		streamVolume = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
//	}
//	
//	public void loadSfx(int raw, int ID){
//		soundPoolMap.put(ID,soundPool.load(context, raw, ID));
//	}
//	
//	public void paly(int sound){
//		soundPool.play(soundPoolMap.get(sound), streamVolume, streamVolume, 1, 0, 1f);
//	}
	/**
	 * 播放系统音效
	 * @param context：产生音效的界面
	 * @param soundID：音效命令
	 */
	private static MediaPlayer mMediaPlayer;

	public static void palySystemSound(Activity context, int soundCommand) {
		if (soundCommand == SoundCommand.START) {
			mMediaPlayer = MediaPlayer.create(context, R.raw.start);
			mMediaPlayer.start();
		} else if (soundCommand == SoundCommand.OVER) {
			mMediaPlayer = MediaPlayer.create(context, R.raw.over);
			mMediaPlayer.start();
		} else if (soundCommand == SoundCommand.RIGHT) {
			mMediaPlayer = MediaPlayer.create(context, R.raw.right);
			mMediaPlayer.start();
		} else if (soundCommand == SoundCommand.LEFT) {
			mMediaPlayer = MediaPlayer.create(context, R.raw.left);
			mMediaPlayer.start();
		} else if (soundCommand == SoundCommand.NEWSTART) {
//			mMediaPlayer = MediaPlayer.create(context, R.raw.newstart);
//			mMediaPlayer.start();
			Toast.makeText(context, "没有找到匹配的语音提示！", Toast.LENGTH_SHORT).show();
		} else if (soundCommand == SoundCommand.NEWOVER) {
//			mMediaPlayer = MediaPlayer.create(context, R.raw.newover);
//			mMediaPlayer.start();
			Toast.makeText(context, "没有找到匹配的语音提示！", Toast.LENGTH_SHORT).show();
		} else if (soundCommand == SoundCommand.NEWRIGHT) {
//			mMediaPlayer = MediaPlayer.create(context, R.raw.newright);
//			mMediaPlayer.start();
			Toast.makeText(context, "没有找到匹配的语音提示！", Toast.LENGTH_SHORT).show();
		} else if (soundCommand == SoundCommand.NEWLEFT) {
//			mMediaPlayer = MediaPlayer.create(context, R.raw.newleft);
//			mMediaPlayer.start();
			Toast.makeText(context, "没有找到匹配的语音提示！", Toast.LENGTH_SHORT).show();
		} else {
			Toast.makeText(context, "没有找到匹配的语音提示！", Toast.LENGTH_SHORT).show();
		}
	}
	
	/**
	 * 播放自己的音效
	 * @param context：产生音效的界面
	 * @param soundID：音效文件ID
	 */
	public static void palyMySound(Activity context, int soundID) {
		mMediaPlayer = MediaPlayer.create(context, soundID);
		mMediaPlayer.start();
	}
	
	/**
	 * 销毁MediaPlayer
	 */
	public static void releaseMediaPlayer(){
		if(mMediaPlayer != null){
			mMediaPlayer.release();
			mMediaPlayer = null;
		}
	}
}
